import java.util.ArrayDeque;

public class MyQueue {

    ArrayDeque<Integer> stack1;//"入队"的元素统一放到stack1中
    ArrayDeque<Integer> stack2;//统一在stack2中出队

    public MyQueue() {
        stack1 = new ArrayDeque<>();
        stack2 = new ArrayDeque<>();
    }

    public void push(int x) {
        stack1.push(x);//"入队"的元素统一放到stack1中
    }

    public int pop() {
        if (stack2.isEmpty()) {
            //若stack2为空，则将stack1中的元素导入stack2中，
            // stack2的栈顶元素即为模拟出队的“队头”元素
            while (!stack1.isEmpty()) {
                int x = stack1.pop();
                stack2.push(x);
            }
            return stack2.pop();
        }else {
            //若stack2不为空，其栈顶元素即为模拟出队的“队头”元素
            return stack2.pop();
        }
    }

    public int peek() {
        if (stack2.isEmpty()) {
            while (!stack1.isEmpty()) {
                int x = stack1.pop();
                stack2.push(x);
            }
            return stack2.peek();
        }else {
            return stack2.peek();
        }
    }

    public boolean empty() {
        //当stack1和stack2均为空时，说明模拟的队列为空
        return stack1.isEmpty() && stack2.isEmpty();
    }
}